// 
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// 
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Lesser General Public License for more details.
// 
// You should have received a copy of the GNU Lesser General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.

//!DESC NNEDI3 (double_y, nns16, win8x4)
//!HOOK LUMA
//!BIND HOOKED
//!SAVE nnedi3_int
//!WHEN HOOKED.h OUTPUT.h / 0.833333 <
float nnedi3(vec4 samples[8]) {
float sum = 0.0, sumsq = 0.0;
for (int i = 0; i < 8; i++) {
    sum += dot(samples[i], vec4(1.0));
    sumsq += dot(samples[i], samples[i]);
}
float mstd0 = sum / 32.0;
float mstd1 = sumsq / 32.0 - mstd0 * mstd0;
float mstd2 = mix(0.0, inversesqrt(mstd1), mstd1 >= 1.192092896e-7);
mstd1 *= mstd2;
float vsum = 0.0, wsum = 0.0, sum1, sum2;
#define T(x) intBitsToFloat(x)
#define W(i,w0,w1,w2,w3) dot(samples[i],vec4(T(w0),T(w1),T(w2),T(w3)))
#define WS(w0,w1) sum1 = exp(sum1 * mstd2 + T(w0)); sum2 = sum2 * mstd2 + T(w1); wsum += sum1; vsum += sum1*(sum2/(1.0+abs(sum2)));
sum1=W(0,-1112248839,1024662558,-1118620174,-1123354974)+W(1,-1143613552,-1129268360,1028038478,1046299686)+W(2,-1087068557,1048182784,-1103968288,1016130204)+W(3,-1103342192,-1115088511,1047279381,1063313277)+W(4,1059583965,-1119323982,-1117908518,-1101453425)+W(5,1003350800,-1134684248,1034186247,-1088182320)+W(6,1027638054,-1137723992,-1122818124,-1122284590)+W(7,-1111377363,1028117438,978245507,-1124394588);sum2=W(0,-1131063526,-1131086728,-1136248556,-1162931039)+W(1,-1117642655,-1128864654,1031011705,1029801649)+W(2,-1128443230,1044675527,-1119907402,-1115594515)+W(3,-1107118398,-1113986381,1050674207,1042762789)+W(4,-1107588397,-1111169922,1017500018,1022791334)+W(5,-1186206458,1017255694,-1112569685,1009001220)+W(6,-1125594766,-1135599628,1014782692,-1156766128)+W(7,993928432,1007622876,-1114139175,-1148613464);WS(1038828992,1041685264);
sum1=W(0,1049950910,1027336960,995958527,-1114329248)+W(1,1028668144,1025858258,-1107326552,-1097681183)+W(2,1060640651,1045782072,1034401008,-1117673776)+W(3,1033402064,-1122828000,-1105157973,-1085831405)+W(4,-1098159517,-1106507532,1035088196,1038612842)+W(5,-1110558370,-1113173980,1032016120,1053136924)+W(6,-1124000392,-1105439902,1029875310,1008781376)+W(7,1012109856,-1114749520,1034119968,1023707152);sum2=W(0,-1099468189,-1140834082,-1131767489,1031315360)+W(1,1036663822,-1122285462,1024287080,-1112139926)+W(2,-1100127579,1052854494,-1107869385,1023637252)+W(3,1038018354,-1112496415,1052996200,-1117241706)+W(4,1034036134,1024451620,-1117110288,-1107666272)+W(5,-1110479054,-1112615559,1027157968,1027811452)+W(6,1003450083,1041131277,-1110538107,-1124350185)+W(7,998992195,-1106762474,1035032776,-1131082337);WS(-1086074680,1053637716);
sum1=W(0,1042002951,-1165378922,-1148805338,-1121345387)+W(1,-1121398619,991217235,-1115297518,-1113042450)+W(2,1052460699,-1094571489,1049266593,-1136570733)+W(3,-1117268427,1036113926,-1098765182,-1107443934)+W(4,-1124281856,1040734807,-1133439181,1027081787)+W(5,-1136658365,-1112513138,1006695533,1043313411)+W(6,-1121708851,1035650578,-1120818857,-1158465386)+W(7,1021173351,-1106476275,1027853163,1016359031);sum2=W(0,-1170492850,1003954710,1017334370,1026517575)+W(1,-1143472678,998846550,-1132363566,-1138816415)+W(2,-1096673587,-1077357700,1071692777,1051558711)+W(3,-1124275402,1018703670,-1098960792,-1136175651)+W(4,-1098179385,996694924,1020207734,1049822619)+W(5,1007812651,1007766851,1003290486,-1116986501)+W(6,-1122577241,1015494226,1019995718,1022251878)+W(7,1009415395,-1163222937,-1126828734,-1141894102);WS(1051521136,1027207116);
sum1=W(0,1010830545,-1124202632,-1121133108,-1122694020)+W(1,1018062184,-1116091286,1037913146,-1124291704)+W(2,1057246783,1026322980,-1116351908,-1102175837)+W(3,1041281977,-1125394504,982577970,-1093542759)+W(4,-1089509425,1025178484,1009393969,1045518980)+W(5,1008755233,-1127575032,-1118947636,1055793637)+W(6,-1117338572,1009646833,1015772516,1008379217)+W(7,1015898776,-1121163492,1001810977,1001093793);sum2=W(0,-1135527491,-1123650952,1013616911,-1137495011)+W(1,-1118108263,-1128775579,1024465134,1027730022)+W(2,1013443151,-1114797945,1029346938,-1135578111)+W(3,-1098008683,-1080443718,1068130737,1049128967)+W(4,-1122100892,-1128721387,1012413655,1017473747)+W(5,-1101482344,-1137148015,-1143058109,1046423571)+W(6,-1166794345,-1156685818,1008139351,-1133405571)+W(7,-1128178767,991435034,-1126785325,1020545683);WS(1057767608,-1132080751);
sum1=W(0,1025766741,-1135552917,1026017621,1026028453)+W(1,1012106581,-1138611630,1040474693,1035118319)+W(2,1051769667,-1083959172,1048679017,-1117947285)+W(3,1030333189,1045191121,-1084413328,-1111744027)+W(4,-1120826122,1045191525,1011196341,1025261389)+W(5,-1122181545,1030480605,-1110336171,1049618505)+W(6,1028389741,1039505775,1025013027,1015828970)+W(7,1027514349,1020294666,-1123719333,1028257397);sum2=W(0,-1101123140,-1103020887,1028118553,1017587161)+W(1,988296658,1010063898,1022642341,1040188371)+W(2,-1099714612,1049070164,1005112948,1008167722)+W(3,1026403646,1033545355,1046164698,1039093756)+W(4,1032013714,1022049457,1015776789,-1125344655)+W(5,1002132020,1037334715,-1098832696,-1111525569)+W(6,1009340114,-1167693540,-1138850406,-1148301500)+W(7,-1139728254,1035581889,-1103378287,-1115917000);WS(-1099372256,-1088618788);
sum1=W(0,1048693927,1033711782,-1113349022,-1112538182)+W(1,-1109099742,-1110127398,-1129092599,-1112344546)+W(2,1064716592,-1143605597,1024020908,-1103996671)+W(3,1032699126,-1121424940,1044926535,-1086749016)+W(4,-1085173359,1004694493,-1111225386,1046614908)+W(5,-1130166943,-1106709441,1040479887,1062252083)+W(6,-1108087402,-1138402062,-1114146165,-1110537326)+W(7,-1120726228,-1106064827,1042110371,1034104622);sum2=W(0,1013472954,-1131186779,-1144106823,987083788)+W(1,979955865,-1163904780,-1122269098,-1120418118)+W(2,-1139561796,1044091298,-1121977305,-1120467381)+W(3,-1115615181,-1127292875,1042996066,1038342084)+W(4,1038343490,-1115306287,-1162389292,-1118651341)+W(5,-1123141745,1014320394,-1128689408,-1118476220)+W(6,-1155962630,-1117365756,964510307,-1152635694)+W(7,-1135582470,1008840046,-1141833923,-1132569906);WS(1041282784,1044242623);
sum1=W(0,-1171512555,-1121861252,-1119816052,-1119885764)+W(1,1025494836,-1113504879,1040963149,1003864029)+W(2,1057266723,1010135439,-1113812594,-1100880653)+W(3,1043843337,-1125989575,-1118004569,-1094412795)+W(4,-1089952515,1031135156,1015358999,1046531310)+W(5,-1156936827,-1122714492,-1114099002,1056310444)+W(6,-1115226950,1003139037,1021011107,1005085853)+W(7,1003362397,-1120612644,992693307,1015234855);sum2=W(0,-1142619324,1012902153,-1143827754,1005317381)+W(1,1026462555,1020893616,-1128784654,-1126266146)+W(2,-1114788024,-1098688460,1009279342,1019060164)+W(3,1054132458,1070492026,-1078812823,-1094218173)+W(4,-1120377499,1017453102,-1131000233,1014092605)+W(5,1048935725,1011358224,1007638067,-1099532818)+W(6,-1139793504,-1147729078,-1137528453,1012779564)+W(7,1015734963,987943782,1018177647,-1130333980);WS(1046635232,1024078131);
sum1=W(0,1035063871,1034039879,1025138813,1002735212)+W(1,1040314319,1035664624,-1105608655,-1097977761)+W(2,1044122447,-1110416695,-1132524982,1017042555)+W(3,1038536855,-1114843703,1051547730,-1094991056)+W(4,-1092481954,-1094320024,1033606155,1031803657)+W(5,1003107468,1019470987,1047410847,1050188814)+W(6,-1107502027,-1103391009,1015508823,1021596219)+W(7,1021345835,-1136683190,1046101811,1031346589);sum2=W(0,1044036812,-1112231286,-1112281069,-1096475926)+W(1,-1106234474,-1121785528,1024115789,1052862983)+W(2,-1111398905,-1096068583,1041647377,-1116645717)+W(3,-1130292776,1037359643,1038036111,1051331710)+W(4,1026411348,-1114320784,1023473494,-1113263240)+W(5,-1111704128,-1123406807,1028002558,1042458641)+W(6,-1138574198,-1104710548,1039764966,-1117017643)+W(7,-1109714921,1041123403,-1106844581,1037890580);WS(-1088554040,-1076674880);
sum1=W(0,-1132973070,1034501898,1016736263,1026292820)+W(1,-1130131975,1028857234,-1110973538,-1144171612)+W(2,-1089525132,1037427962,-1110236986,1042339025)+W(3,-1108906970,-1112145786,-1123890785,1052671191)+W(4,1056478885,-1118983748,1016313655,-1103961368)+W(5,1002874044,1025897228,1041641985,-1092344862)+W(6,1038469390,-1123320716,1014755782,-1151588920)+W(7,-1130905399,1033705562,1017396903,1010979982);sum2=W(0,-1133182691,1024414743,1007730851,1013915195)+W(1,1020584890,1005058566,-1121307593,-1127318198)+W(2,-1111248658,1040952978,1028189234,981970521)+W(3,-1124411850,1029625115,1057294107,1035588225)+W(4,-1109339192,-1094377458,-1142484934,-1121038101)+W(5,1026110889,1023925523,1024397525,-1107404728)+W(6,-1116592821,-1112421528,1010322539,-1146368902)+W(7,-1140327971,-1199698720,1019759378,-1118541421);WS(1063581112,1015292283);
sum1=W(0,-1125096044,1037634467,-1124445804,-1123806598)+W(1,-1117498166,1006823135,1028314614,1046804719)+W(2,-1083793455,-1098422117,-1112186771,1036776315)+W(3,-1106689849,1004978479,1034155462,1064148787)+W(4,1058965073,-1106625757,-1117642958,-1102837698)+W(5,1033810693,1029436414,1037373467,-1089226130)+W(6,1036181095,-1127761788,1010580432,-1137018200)+W(7,-1119765454,1034713459,1021285644,994321759);sum2=W(0,-1110373665,-1122115974,-1129458054,-1127012521)+W(1,1021812843,1015201109,-1121551577,-1121983257)+W(2,-1118435057,1041258512,-1113739078,-1134632819)+W(3,1039413537,-1127386873,1043546644,-1107711610)+W(4,1025961773,1041055451,-1115241196,-1106078947)+W(5,-1110385416,-1135801459,-1131486243,1048226293)+W(6,1025056413,1029845331,-1119046895,-1122814807)+W(7,-1132245806,-1140149017,1018415015,-1139476701);WS(-1109010880,-1087548956);
sum1=W(0,-1095012676,-1102610188,1034343312,1034947768)+W(1,1029737824,1025692706,1039446704,1046023882)+W(2,-1096454908,-1091443170,1019661856,1016751552)+W(3,1038373096,1039271048,-1105694067,1042564604)+W(4,-1131030249,1042942296,1017025648,-1126501287)+W(5,1012879825,1041317114,-1103700296,1044246468)+W(6,1019936112,1024647464,-1140792121,1030724160)+W(7,1029263800,1041193844,-1107855416,-1141422594);sum2=W(0,-1107522705,-1121503695,-1113997103,1034034732)+W(1,1021740679,-1112744336,1038975878,-1105460279)+W(2,-1114143244,-1105773446,1025456143,1028771217)+W(3,-1121564954,1024971971,1059420344,1032873918)+W(4,-1109746606,-1106040358,-1102403849,1035315492)+W(5,-1122379806,-1106873869,1046039582,1040681265)+W(6,-1106459627,1039219872,-1099438501,1018212015)+W(7,-1130313815,-1105420350,1046943722,1026290649);WS(-1086299832,-1077288694);
sum1=W(0,-1099039878,-1108540692,-1132921948,1021716686)+W(1,1039618828,-1131678690,1021468846,-1111509136)+W(2,-1158126306,1055092577,-1108835908,-1113901292)+W(3,1041516082,-1118733319,1062013047,-1096197083)+W(4,-1089051407,-1113759276,965138311,1023078294)+W(5,-1122936235,1015065790,1022391342,1050708993)+W(6,-1107695832,-1113503632,-1130194922,998651320)+W(7,997649137,1023538631,991635057,-1133490396);sum2=W(0,1035891239,1030599513,1027343155,-1133976495)+W(1,-1113698362,1016406968,-1108453664,-1130801609)+W(2,1037590422,1054189655,-1119506980,-1149877867)+W(3,-1108226898,-1120928356,-1119322812,1012747883)+W(4,1041308688,-1112736561,1016526837,-1126385541)+W(5,1016225738,988482485,-1119223720,-1107379808)+W(6,1004824957,-1120347934,-1140785051,994153115)+W(7,1018050885,-1117792638,-1129452107,-1116360142);WS(-1113279936,1066223903);
sum1=W(0,1040261344,-1140107833,-1141738481,-1128171420)+W(1,-1123695998,-1154978689,-1116929726,-1112013315)+W(2,1050703688,-1100167260,1044160156,-1138940153)+W(3,-1123177006,1034288823,-1100730273,-1108200895)+W(4,-1130335589,1035637471,-1129655596,1020686276)+W(5,-1141423761,-1114187043,1024316286,1040782300)+W(6,-1124525100,1032644739,-1123239900,964173357)+W(7,1013984857,-1108229911,1029624526,1014134393);sum2=W(0,1021458196,1017345212,-1125272644,-1115606620)+W(1,-1131253088,-1143902384,1016051020,1009639320)+W(2,1047257730,1068148121,-1080575150,-1099614716)+W(3,1020803060,1032085971,-1113655261,-1120838650)+W(4,1044966894,1026244022,-1122847678,-1102155153)+W(5,1016311348,-1137376840,-1130782536,-1132238288)+W(6,1017049220,1010161976,-1129056732,-1123394906)+W(7,-1137115752,-1136984808,1004223696,967940860);WS(1060545080,-1126581603);
sum1=W(0,-1112268976,-1128752350,1037657648,1032630360)+W(1,-1125010622,1029508223,1032285712,1045186906)+W(2,-1090205186,1048595306,1037448680,1043836232)+W(3,-1108078856,1041691860,-1094666759,1053340438)+W(4,1057651571,1035187792,1031833596,976149203)+W(5,1042698525,1040118132,-1092127852,-1082657749)+W(6,1034806588,1043419290,1025282125,1031675647)+W(7,1033087420,1034587656,-1096441814,-1104761760);sum2=W(0,1034075649,1026991402,-1126365381,-1123698886)+W(1,-1113635181,-1168196508,-1118780236,998149095)+W(2,1019253181,1047572688,-1121651762,-1135914762)+W(3,-1114469118,-1145545780,1038479879,1023543366)+W(4,1035108181,-1115886918,-1122087574,-1118625490)+W(5,992781287,-1139655050,1011684618,-1114677625)+W(6,1016718341,-1117034488,-1134045690,-1147908244)+W(7,-1142844852,1007905050,-1137057610,-1132109957);WS(-1083899832,-1105526146);
sum1=W(0,-1119744955,-1125720471,-1139718894,1026357515)+W(1,-1111407198,-1152407445,-1106102943,-1117075907)+W(2,-1092285679,1062437883,-1105573131,1044187583)+W(3,-1107209883,-1107292779,1052836221,1048719011)+W(4,1058460257,1022150135,-1119529939,-1104526300)+W(5,-1122559055,-1119739267,-1123085499,-1089717563)+W(6,1033366698,1009731342,-1132776678,-1125768375)+W(7,-1119196243,-1129505495,-1112611206,-1114009838);sum2=W(0,1025172792,-1117035240,-1129400032,-1110807022)+W(1,-1123816828,-1144812946,999654946,1033543849)+W(2,1035443403,-1135427545,-1123619892,-1105612607)+W(3,-1120747576,-1113498942,1053020794,1039345667)+W(4,-1111010692,-1115955576,1016529300,-1131262448)+W(5,-1113301822,-1146605522,-1135856481,1047843748)+W(6,-1117326476,-1121250556,-1136239801,-1129444600)+W(7,-1119691028,-1135792457,998047364,1022819536);WS(-1107513792,1064663354);
sum1=W(0,-1113532308,1021510766,-1161118946,1030862455)+W(1,-1123071015,1009770420,-1127591630,1032378968)+W(2,-1091621085,1046262406,-1104300038,1040244826)+W(3,-1107582956,-1108820108,1034822530,1051734861)+W(4,1054782000,1019068110,-1135077628,-1102940181)+W(5,-1125175670,1025488559,1031948820,-1095483267)+W(6,1036941280,-1128724830,1011863892,-1135539484)+W(7,-1126076542,1036426604,-1120336759,-1172984259);sum2=W(0,-1140752647,-1123380440,-1139065871,-1135206239)+W(1,974924014,-1133276463,1021581075,1022777359)+W(2,988696695,-1092786651,1025917606,1026230428)+W(3,1029689087,-1140169471,-1085937537,-1122295168)+W(4,1049996339,1057784826,1013849783,1027050280)+W(5,-1135329695,-1124883951,-1130048007,1032573953)+W(6,1033822297,1034470972,-1127829351,1016077019)+W(7,1011238415,1001568686,-1137094527,1032545188);WS(1058918200,-1121082995);
return clamp(mstd0 + 5.0 * vsum / wsum * mstd1, 0.0, 1.0);
}  // nnedi3
vec4 hook() {
vec4 ret = vec4(0.0);
vec4 samples[8];
samples[0] = HOOKED_mul * textureGatherOffset(HOOKED_raw, HOOKED_pos, ivec2(-3, -1), 0);
samples[1] = HOOKED_mul * textureGatherOffset(HOOKED_raw, HOOKED_pos, ivec2(-3, 1), 0);
samples[2] = HOOKED_mul * textureGatherOffset(HOOKED_raw, HOOKED_pos, ivec2(-1, -1), 0);
samples[3] = HOOKED_mul * textureGatherOffset(HOOKED_raw, HOOKED_pos, ivec2(-1, 1), 0);
samples[4] = HOOKED_mul * textureGatherOffset(HOOKED_raw, HOOKED_pos, ivec2(1, -1), 0);
samples[5] = HOOKED_mul * textureGatherOffset(HOOKED_raw, HOOKED_pos, ivec2(1, 1), 0);
samples[6] = HOOKED_mul * textureGatherOffset(HOOKED_raw, HOOKED_pos, ivec2(3, -1), 0);
samples[7] = HOOKED_mul * textureGatherOffset(HOOKED_raw, HOOKED_pos, ivec2(3, 1), 0);
ret[0] = nnedi3(samples);
return ret;
}  // hook
//!DESC NNEDI3 (combine_y, nns16, win8x4)
//!HOOK LUMA
//!BIND HOOKED
//!BIND nnedi3_int
//!HEIGHT 2 HOOKED.h *
//!OFFSET 0.000000 -0.500000
//!WHEN HOOKED.h OUTPUT.h / 0.833333 <
vec4 hook() {
    vec2 dir = fract(HOOKED_pos * HOOKED_size) - 0.5;
    if (dir.y < 0.0) {
        return HOOKED_texOff(-dir);
    } else {
        return nnedi3_int_texOff(-dir);
    }
}
//!DESC NNEDI3 (double_x, nns16, win8x4)
//!HOOK LUMA
//!BIND HOOKED
//!SAVE nnedi3_int
//!WHEN HOOKED.w OUTPUT.w / 0.833333 <
float nnedi3(vec4 samples[8]) {
float sum = 0.0, sumsq = 0.0;
for (int i = 0; i < 8; i++) {
    sum += dot(samples[i], vec4(1.0));
    sumsq += dot(samples[i], samples[i]);
}
float mstd0 = sum / 32.0;
float mstd1 = sumsq / 32.0 - mstd0 * mstd0;
float mstd2 = mix(0.0, inversesqrt(mstd1), mstd1 >= 1.192092896e-7);
mstd1 *= mstd2;
float vsum = 0.0, wsum = 0.0, sum1, sum2;
#define T(x) intBitsToFloat(x)
#define W(i,w0,w1,w2,w3) dot(samples[i],vec4(T(w0),T(w1),T(w2),T(w3)))
#define WS(w0,w1) sum1 = exp(sum1 * mstd2 + T(w0)); sum2 = sum2 * mstd2 + T(w1); wsum += sum1; vsum += sum1*(sum2/(1.0+abs(sum2)));
sum1=W(0,-1118620174,1024662558,-1112248839,-1123354974)+W(1,-1103968288,1048182784,-1087068557,1016130204)+W(2,-1117908518,-1119323982,1059583965,-1101453425)+W(3,-1122818124,-1137723992,1027638054,-1122284590)+W(4,1028038478,-1129268360,-1143613552,1046299686)+W(5,1047279381,-1115088511,-1103342192,1063313277)+W(6,1034186247,-1134684248,1003350800,-1088182320)+W(7,978245507,1028117438,-1111377363,-1124394588);sum2=W(0,-1136248556,-1131086728,-1131063526,-1162931039)+W(1,-1119907402,1044675527,-1128443230,-1115594515)+W(2,1017500018,-1111169922,-1107588397,1022791334)+W(3,1014782692,-1135599628,-1125594766,-1156766128)+W(4,1031011705,-1128864654,-1117642655,1029801649)+W(5,1050674207,-1113986381,-1107118398,1042762789)+W(6,-1112569685,1017255694,-1186206458,1009001220)+W(7,-1114139175,1007622876,993928432,-1148613464);WS(1038828992,1041685264);
sum1=W(0,995958527,1027336960,1049950910,-1114329248)+W(1,1034401008,1045782072,1060640651,-1117673776)+W(2,1035088196,-1106507532,-1098159517,1038612842)+W(3,1029875310,-1105439902,-1124000392,1008781376)+W(4,-1107326552,1025858258,1028668144,-1097681183)+W(5,-1105157973,-1122828000,1033402064,-1085831405)+W(6,1032016120,-1113173980,-1110558370,1053136924)+W(7,1034119968,-1114749520,1012109856,1023707152);sum2=W(0,-1131767489,-1140834082,-1099468189,1031315360)+W(1,-1107869385,1052854494,-1100127579,1023637252)+W(2,-1117110288,1024451620,1034036134,-1107666272)+W(3,-1110538107,1041131277,1003450083,-1124350185)+W(4,1024287080,-1122285462,1036663822,-1112139926)+W(5,1052996200,-1112496415,1038018354,-1117241706)+W(6,1027157968,-1112615559,-1110479054,1027811452)+W(7,1035032776,-1106762474,998992195,-1131082337);WS(-1086074680,1053637716);
sum1=W(0,-1148805338,-1165378922,1042002951,-1121345387)+W(1,1049266593,-1094571489,1052460699,-1136570733)+W(2,-1133439181,1040734807,-1124281856,1027081787)+W(3,-1120818857,1035650578,-1121708851,-1158465386)+W(4,-1115297518,991217235,-1121398619,-1113042450)+W(5,-1098765182,1036113926,-1117268427,-1107443934)+W(6,1006695533,-1112513138,-1136658365,1043313411)+W(7,1027853163,-1106476275,1021173351,1016359031);sum2=W(0,1017334370,1003954710,-1170492850,1026517575)+W(1,1071692777,-1077357700,-1096673587,1051558711)+W(2,1020207734,996694924,-1098179385,1049822619)+W(3,1019995718,1015494226,-1122577241,1022251878)+W(4,-1132363566,998846550,-1143472678,-1138816415)+W(5,-1098960792,1018703670,-1124275402,-1136175651)+W(6,1003290486,1007766851,1007812651,-1116986501)+W(7,-1126828734,-1163222937,1009415395,-1141894102);WS(1051521136,1027207116);
sum1=W(0,-1121133108,-1124202632,1010830545,-1122694020)+W(1,-1116351908,1026322980,1057246783,-1102175837)+W(2,1009393969,1025178484,-1089509425,1045518980)+W(3,1015772516,1009646833,-1117338572,1008379217)+W(4,1037913146,-1116091286,1018062184,-1124291704)+W(5,982577970,-1125394504,1041281977,-1093542759)+W(6,-1118947636,-1127575032,1008755233,1055793637)+W(7,1001810977,-1121163492,1015898776,1001093793);sum2=W(0,1013616911,-1123650952,-1135527491,-1137495011)+W(1,1029346938,-1114797945,1013443151,-1135578111)+W(2,1012413655,-1128721387,-1122100892,1017473747)+W(3,1008139351,-1156685818,-1166794345,-1133405571)+W(4,1024465134,-1128775579,-1118108263,1027730022)+W(5,1068130737,-1080443718,-1098008683,1049128967)+W(6,-1143058109,-1137148015,-1101482344,1046423571)+W(7,-1126785325,991435034,-1128178767,1020545683);WS(1057767608,-1132080751);
sum1=W(0,1026017621,-1135552917,1025766741,1026028453)+W(1,1048679017,-1083959172,1051769667,-1117947285)+W(2,1011196341,1045191525,-1120826122,1025261389)+W(3,1025013027,1039505775,1028389741,1015828970)+W(4,1040474693,-1138611630,1012106581,1035118319)+W(5,-1084413328,1045191121,1030333189,-1111744027)+W(6,-1110336171,1030480605,-1122181545,1049618505)+W(7,-1123719333,1020294666,1027514349,1028257397);sum2=W(0,1028118553,-1103020887,-1101123140,1017587161)+W(1,1005112948,1049070164,-1099714612,1008167722)+W(2,1015776789,1022049457,1032013714,-1125344655)+W(3,-1138850406,-1167693540,1009340114,-1148301500)+W(4,1022642341,1010063898,988296658,1040188371)+W(5,1046164698,1033545355,1026403646,1039093756)+W(6,-1098832696,1037334715,1002132020,-1111525569)+W(7,-1103378287,1035581889,-1139728254,-1115917000);WS(-1099372256,-1088618788);
sum1=W(0,-1113349022,1033711782,1048693927,-1112538182)+W(1,1024020908,-1143605597,1064716592,-1103996671)+W(2,-1111225386,1004694493,-1085173359,1046614908)+W(3,-1114146165,-1138402062,-1108087402,-1110537326)+W(4,-1129092599,-1110127398,-1109099742,-1112344546)+W(5,1044926535,-1121424940,1032699126,-1086749016)+W(6,1040479887,-1106709441,-1130166943,1062252083)+W(7,1042110371,-1106064827,-1120726228,1034104622);sum2=W(0,-1144106823,-1131186779,1013472954,987083788)+W(1,-1121977305,1044091298,-1139561796,-1120467381)+W(2,-1162389292,-1115306287,1038343490,-1118651341)+W(3,964510307,-1117365756,-1155962630,-1152635694)+W(4,-1122269098,-1163904780,979955865,-1120418118)+W(5,1042996066,-1127292875,-1115615181,1038342084)+W(6,-1128689408,1014320394,-1123141745,-1118476220)+W(7,-1141833923,1008840046,-1135582470,-1132569906);WS(1041282784,1044242623);
sum1=W(0,-1119816052,-1121861252,-1171512555,-1119885764)+W(1,-1113812594,1010135439,1057266723,-1100880653)+W(2,1015358999,1031135156,-1089952515,1046531310)+W(3,1021011107,1003139037,-1115226950,1005085853)+W(4,1040963149,-1113504879,1025494836,1003864029)+W(5,-1118004569,-1125989575,1043843337,-1094412795)+W(6,-1114099002,-1122714492,-1156936827,1056310444)+W(7,992693307,-1120612644,1003362397,1015234855);sum2=W(0,-1143827754,1012902153,-1142619324,1005317381)+W(1,1009279342,-1098688460,-1114788024,1019060164)+W(2,-1131000233,1017453102,-1120377499,1014092605)+W(3,-1137528453,-1147729078,-1139793504,1012779564)+W(4,-1128784654,1020893616,1026462555,-1126266146)+W(5,-1078812823,1070492026,1054132458,-1094218173)+W(6,1007638067,1011358224,1048935725,-1099532818)+W(7,1018177647,987943782,1015734963,-1130333980);WS(1046635232,1024078131);
sum1=W(0,1025138813,1034039879,1035063871,1002735212)+W(1,-1132524982,-1110416695,1044122447,1017042555)+W(2,1033606155,-1094320024,-1092481954,1031803657)+W(3,1015508823,-1103391009,-1107502027,1021596219)+W(4,-1105608655,1035664624,1040314319,-1097977761)+W(5,1051547730,-1114843703,1038536855,-1094991056)+W(6,1047410847,1019470987,1003107468,1050188814)+W(7,1046101811,-1136683190,1021345835,1031346589);sum2=W(0,-1112281069,-1112231286,1044036812,-1096475926)+W(1,1041647377,-1096068583,-1111398905,-1116645717)+W(2,1023473494,-1114320784,1026411348,-1113263240)+W(3,1039764966,-1104710548,-1138574198,-1117017643)+W(4,1024115789,-1121785528,-1106234474,1052862983)+W(5,1038036111,1037359643,-1130292776,1051331710)+W(6,1028002558,-1123406807,-1111704128,1042458641)+W(7,-1106844581,1041123403,-1109714921,1037890580);WS(-1088554040,-1076674880);
sum1=W(0,1016736263,1034501898,-1132973070,1026292820)+W(1,-1110236986,1037427962,-1089525132,1042339025)+W(2,1016313655,-1118983748,1056478885,-1103961368)+W(3,1014755782,-1123320716,1038469390,-1151588920)+W(4,-1110973538,1028857234,-1130131975,-1144171612)+W(5,-1123890785,-1112145786,-1108906970,1052671191)+W(6,1041641985,1025897228,1002874044,-1092344862)+W(7,1017396903,1033705562,-1130905399,1010979982);sum2=W(0,1007730851,1024414743,-1133182691,1013915195)+W(1,1028189234,1040952978,-1111248658,981970521)+W(2,-1142484934,-1094377458,-1109339192,-1121038101)+W(3,1010322539,-1112421528,-1116592821,-1146368902)+W(4,-1121307593,1005058566,1020584890,-1127318198)+W(5,1057294107,1029625115,-1124411850,1035588225)+W(6,1024397525,1023925523,1026110889,-1107404728)+W(7,1019759378,-1199698720,-1140327971,-1118541421);WS(1063581112,1015292283);
sum1=W(0,-1124445804,1037634467,-1125096044,-1123806598)+W(1,-1112186771,-1098422117,-1083793455,1036776315)+W(2,-1117642958,-1106625757,1058965073,-1102837698)+W(3,1010580432,-1127761788,1036181095,-1137018200)+W(4,1028314614,1006823135,-1117498166,1046804719)+W(5,1034155462,1004978479,-1106689849,1064148787)+W(6,1037373467,1029436414,1033810693,-1089226130)+W(7,1021285644,1034713459,-1119765454,994321759);sum2=W(0,-1129458054,-1122115974,-1110373665,-1127012521)+W(1,-1113739078,1041258512,-1118435057,-1134632819)+W(2,-1115241196,1041055451,1025961773,-1106078947)+W(3,-1119046895,1029845331,1025056413,-1122814807)+W(4,-1121551577,1015201109,1021812843,-1121983257)+W(5,1043546644,-1127386873,1039413537,-1107711610)+W(6,-1131486243,-1135801459,-1110385416,1048226293)+W(7,1018415015,-1140149017,-1132245806,-1139476701);WS(-1109010880,-1087548956);
sum1=W(0,1034343312,-1102610188,-1095012676,1034947768)+W(1,1019661856,-1091443170,-1096454908,1016751552)+W(2,1017025648,1042942296,-1131030249,-1126501287)+W(3,-1140792121,1024647464,1019936112,1030724160)+W(4,1039446704,1025692706,1029737824,1046023882)+W(5,-1105694067,1039271048,1038373096,1042564604)+W(6,-1103700296,1041317114,1012879825,1044246468)+W(7,-1107855416,1041193844,1029263800,-1141422594);sum2=W(0,-1113997103,-1121503695,-1107522705,1034034732)+W(1,1025456143,-1105773446,-1114143244,1028771217)+W(2,-1102403849,-1106040358,-1109746606,1035315492)+W(3,-1099438501,1039219872,-1106459627,1018212015)+W(4,1038975878,-1112744336,1021740679,-1105460279)+W(5,1059420344,1024971971,-1121564954,1032873918)+W(6,1046039582,-1106873869,-1122379806,1040681265)+W(7,1046943722,-1105420350,-1130313815,1026290649);WS(-1086299832,-1077288694);
sum1=W(0,-1132921948,-1108540692,-1099039878,1021716686)+W(1,-1108835908,1055092577,-1158126306,-1113901292)+W(2,965138311,-1113759276,-1089051407,1023078294)+W(3,-1130194922,-1113503632,-1107695832,998651320)+W(4,1021468846,-1131678690,1039618828,-1111509136)+W(5,1062013047,-1118733319,1041516082,-1096197083)+W(6,1022391342,1015065790,-1122936235,1050708993)+W(7,991635057,1023538631,997649137,-1133490396);sum2=W(0,1027343155,1030599513,1035891239,-1133976495)+W(1,-1119506980,1054189655,1037590422,-1149877867)+W(2,1016526837,-1112736561,1041308688,-1126385541)+W(3,-1140785051,-1120347934,1004824957,994153115)+W(4,-1108453664,1016406968,-1113698362,-1130801609)+W(5,-1119322812,-1120928356,-1108226898,1012747883)+W(6,-1119223720,988482485,1016225738,-1107379808)+W(7,-1129452107,-1117792638,1018050885,-1116360142);WS(-1113279936,1066223903);
sum1=W(0,-1141738481,-1140107833,1040261344,-1128171420)+W(1,1044160156,-1100167260,1050703688,-1138940153)+W(2,-1129655596,1035637471,-1130335589,1020686276)+W(3,-1123239900,1032644739,-1124525100,964173357)+W(4,-1116929726,-1154978689,-1123695998,-1112013315)+W(5,-1100730273,1034288823,-1123177006,-1108200895)+W(6,1024316286,-1114187043,-1141423761,1040782300)+W(7,1029624526,-1108229911,1013984857,1014134393);sum2=W(0,-1125272644,1017345212,1021458196,-1115606620)+W(1,-1080575150,1068148121,1047257730,-1099614716)+W(2,-1122847678,1026244022,1044966894,-1102155153)+W(3,-1129056732,1010161976,1017049220,-1123394906)+W(4,1016051020,-1143902384,-1131253088,1009639320)+W(5,-1113655261,1032085971,1020803060,-1120838650)+W(6,-1130782536,-1137376840,1016311348,-1132238288)+W(7,1004223696,-1136984808,-1137115752,967940860);WS(1060545080,-1126581603);
sum1=W(0,1037657648,-1128752350,-1112268976,1032630360)+W(1,1037448680,1048595306,-1090205186,1043836232)+W(2,1031833596,1035187792,1057651571,976149203)+W(3,1025282125,1043419290,1034806588,1031675647)+W(4,1032285712,1029508223,-1125010622,1045186906)+W(5,-1094666759,1041691860,-1108078856,1053340438)+W(6,-1092127852,1040118132,1042698525,-1082657749)+W(7,-1096441814,1034587656,1033087420,-1104761760);sum2=W(0,-1126365381,1026991402,1034075649,-1123698886)+W(1,-1121651762,1047572688,1019253181,-1135914762)+W(2,-1122087574,-1115886918,1035108181,-1118625490)+W(3,-1134045690,-1117034488,1016718341,-1147908244)+W(4,-1118780236,-1168196508,-1113635181,998149095)+W(5,1038479879,-1145545780,-1114469118,1023543366)+W(6,1011684618,-1139655050,992781287,-1114677625)+W(7,-1137057610,1007905050,-1142844852,-1132109957);WS(-1083899832,-1105526146);
sum1=W(0,-1139718894,-1125720471,-1119744955,1026357515)+W(1,-1105573131,1062437883,-1092285679,1044187583)+W(2,-1119529939,1022150135,1058460257,-1104526300)+W(3,-1132776678,1009731342,1033366698,-1125768375)+W(4,-1106102943,-1152407445,-1111407198,-1117075907)+W(5,1052836221,-1107292779,-1107209883,1048719011)+W(6,-1123085499,-1119739267,-1122559055,-1089717563)+W(7,-1112611206,-1129505495,-1119196243,-1114009838);sum2=W(0,-1129400032,-1117035240,1025172792,-1110807022)+W(1,-1123619892,-1135427545,1035443403,-1105612607)+W(2,1016529300,-1115955576,-1111010692,-1131262448)+W(3,-1136239801,-1121250556,-1117326476,-1129444600)+W(4,999654946,-1144812946,-1123816828,1033543849)+W(5,1053020794,-1113498942,-1120747576,1039345667)+W(6,-1135856481,-1146605522,-1113301822,1047843748)+W(7,998047364,-1135792457,-1119691028,1022819536);WS(-1107513792,1064663354);
sum1=W(0,-1161118946,1021510766,-1113532308,1030862455)+W(1,-1104300038,1046262406,-1091621085,1040244826)+W(2,-1135077628,1019068110,1054782000,-1102940181)+W(3,1011863892,-1128724830,1036941280,-1135539484)+W(4,-1127591630,1009770420,-1123071015,1032378968)+W(5,1034822530,-1108820108,-1107582956,1051734861)+W(6,1031948820,1025488559,-1125175670,-1095483267)+W(7,-1120336759,1036426604,-1126076542,-1172984259);sum2=W(0,-1139065871,-1123380440,-1140752647,-1135206239)+W(1,1025917606,-1092786651,988696695,1026230428)+W(2,1013849783,1057784826,1049996339,1027050280)+W(3,-1127829351,1034470972,1033822297,1016077019)+W(4,1021581075,-1133276463,974924014,1022777359)+W(5,-1085937537,-1140169471,1029689087,-1122295168)+W(6,-1130048007,-1124883951,-1135329695,1032573953)+W(7,-1137094527,1001568686,1011238415,1032545188);WS(1058918200,-1121082995);
return clamp(mstd0 + 5.0 * vsum / wsum * mstd1, 0.0, 1.0);
}  // nnedi3
vec4 hook() {
vec4 ret = vec4(0.0);
vec4 samples[8];
samples[0] = HOOKED_mul * textureGatherOffset(HOOKED_raw, HOOKED_pos, ivec2(-1, -3), 0);
samples[1] = HOOKED_mul * textureGatherOffset(HOOKED_raw, HOOKED_pos, ivec2(-1, -1), 0);
samples[2] = HOOKED_mul * textureGatherOffset(HOOKED_raw, HOOKED_pos, ivec2(-1, 1), 0);
samples[3] = HOOKED_mul * textureGatherOffset(HOOKED_raw, HOOKED_pos, ivec2(-1, 3), 0);
samples[4] = HOOKED_mul * textureGatherOffset(HOOKED_raw, HOOKED_pos, ivec2(1, -3), 0);
samples[5] = HOOKED_mul * textureGatherOffset(HOOKED_raw, HOOKED_pos, ivec2(1, -1), 0);
samples[6] = HOOKED_mul * textureGatherOffset(HOOKED_raw, HOOKED_pos, ivec2(1, 1), 0);
samples[7] = HOOKED_mul * textureGatherOffset(HOOKED_raw, HOOKED_pos, ivec2(1, 3), 0);
ret[0] = nnedi3(samples);
return ret;
}  // hook
//!DESC NNEDI3 (combine_x, nns16, win8x4)
//!HOOK LUMA
//!BIND HOOKED
//!BIND nnedi3_int
//!WIDTH 2 HOOKED.w *
//!OFFSET -0.500000 0.000000
//!WHEN HOOKED.w OUTPUT.w / 0.833333 <
vec4 hook() {
    vec2 dir = fract(HOOKED_pos * HOOKED_size) - 0.5;
    if (dir.x < 0.0) {
        return HOOKED_texOff(-dir);
    } else {
        return nnedi3_int_texOff(-dir);
    }
}
